param(
    [string]$EnvDir = ".venv"
)

Write-Host "=== PSD Tools 环境安装脚本 ==="

try {
    $pythonCmd = (Get-Command python -ErrorAction Stop).Path
} catch {
    Write-Error "未检测到 Python，可从 https://www.python.org/downloads/ 安装后重试。"
    exit 1
}

if (-not (Test-Path $EnvDir)) {
    Write-Host "创建虚拟环境: $EnvDir"
    & $pythonCmd -m venv $EnvDir
    if ($LASTEXITCODE -ne 0) {
        Write-Error "虚拟环境创建失败。"
        exit 1
    }
}

if (Test-Path $EnvDir) {
    Write-Host "检测到虚拟环境: $EnvDir"
}

$venvPython = Join-Path $EnvDir "Scripts/python.exe"
if (-not (Test-Path $venvPython)) {
    Write-Error "未找到虚拟环境 Python: $venvPython"
    exit 1
}

Write-Host "升级 pip"
& $venvPython -m pip install --upgrade pip
if ($LASTEXITCODE -ne 0) {
    Write-Error "pip 升级失败。"
    exit 1
}

























































































































































































































































































































































































































































































































































Write-Host "安装 psd-tools"
& $venvPython -m pip install psd-tools
if ($LASTEXITCODE -ne 0) {
    Write-Error "psd-tools 安装失败。"
    exit 1
}

Write-Host "安装完成。使用以下命令激活虚拟环境："
$activateScript = Join-Path $EnvDir "Scripts/activate.ps1"
Write-Host ("    . {0}" -f $activateScript)
